package vno.fux.res.manager
{
	import vno.fux.GlobalVar;
	import vno.fux.res.pool.NpcResource;
	import vno.fux.res.pool.RM_URM;
	import vno.fux.res.pool.ResourcePool;
	import flash.utils.getQualifiedClassName;
	import vno.fux.res.pool.Resource;
	
	internal class UiResourceManager
	{
		public static var instance:UiResourceManager;
		private const obj_id:String = "RM_URM";
		private var _resourcePool:ResourcePool;
		private var _loaderManager:LoaderManager;
		private var _resInfo:XML;
		
		public function UiResourceManager(pvt:PrivateClass, resInfo_:XML)
		{
			_resourcePool = ResourcePool.getInstance();
			_loaderManager =  ResourceManager.loader;
			_resInfo = resInfo_;
		}
		
		public function load(id:uint):void
		{
			use namespace RM_URM;
			//trace(getQualifiedClassName(_chaResInfo..res.(@id==id)[0]));
			for each(var res:XML in _resInfo.assets.(@id==id)[0].elements())
			{
				var url:String = res.@url;
				var uiRes:Resource = _resourcePool.uiRes.getRes(id);
				var mission:ResourceMission = new ResourceMission(GlobalVar.webUrl+url, uiRes["_"+res.name()], CommonLoader.PIC, uiRes, _loaderManager.getId());
				_loaderManager.addMission(mission);
			}
		}
		
		public static function init(resInfo_:XML):void
		{
			if(UiResourceManager.instance)
			{
				throw new Error("You can't init the UiResourceManager twice!")
			}
			UiResourceManager.instance = new UiResourceManager(new PrivateClass, resInfo_);
		}
		
		public static function getInstance():UiResourceManager
		{
			return UiResourceManager.instance;
		}
	}
}
class PrivateClass
{
	public function PrivateClass()
	{
	}
}